/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 * 
 */
package spwodne;

import java.awt.AWTKeyStroke;
import java.awt.event.*;
import java.util.HashSet;
import java.util.Set;
import javax.swing.*;
import org.jdesktop.layout.GroupLayout;

public class ONaleznosc extends JFrame {

    public ONaleznosc(MTNaleznosci mtn, OEKlient oek) {
        this.mtn = mtn;
        this.oek = oek;
        initComponents();
    }

    private void initComponents() {
        Set secik = new HashSet();
        secik.add(AWTKeyStroke.getAWTKeyStroke(10, 0));
        setFocusTraversalKeys(0, secik);
        jPanel1 = new JPanel();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        jTextField1 = new JTextField();
        jTextField2 = new JTextField();
        jButton1 = new JButton();
        jButton2 = new JButton();
        setDefaultCloseOperation(2);
        jPanel1.setBorder(BorderFactory.createTitledBorder("Nowa Nale\u017Cno\u015B\u0107"));
        jPanel1.addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent evt) {
                jPanel1KeyPressed(evt);
            }
            final ONaleznosc this$0;
            

            {
                this$0 = ONaleznosc.this;
            //super();
            }
        });
        jLabel1.setText("Kwota");
        jLabel2.setText("Rok");
        jLabel3.setText("[z\u0142]");
        jTextField1.setHorizontalAlignment(4);
        jTextField1.setText("0.0");
        jTextField2.setHorizontalAlignment(4);
        jTextField2.setText("2002");
        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(1).add(jLabel1).add(jLabel2)).addPreferredGap(0).add(jPanel1Layout.createParallelGroup(1, false).add(jTextField2).add(jTextField1, -1, 54, 32767)).addPreferredGap(0).add(jLabel3).addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().add(jPanel1Layout.createParallelGroup(3).add(jLabel3).add(jLabel1).add(jTextField1, -2, -1, -2)).addPreferredGap(0).add(jPanel1Layout.createParallelGroup(3).add(jLabel2).add(jTextField2, -2, -1, -2)).addContainerGap(14, 32767)));
        jButton1.setText("OK");
        jButton1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
            final ONaleznosc this$0;
            

            {
                this$0 = ONaleznosc.this;
            //super();
            }
        });
        jButton2.setText("anuluj");
        jButton2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
            final ONaleznosc this$0;
            

            {
                this$0 = ONaleznosc.this;
            //super();
            }
        });
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(layout.createParallelGroup(1).add(jPanel1, -2, -1, -2).add(2, layout.createSequentialGroup().add(jButton1, -2, 73, -2).addPreferredGap(0).add(jButton2))).addContainerGap(-1, 32767)));
        layout.setVerticalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(jPanel1, -2, -1, -2).addPreferredGap(0).add(layout.createParallelGroup(3).add(jButton2).add(jButton1)).addContainerGap(-1, 32767)));
        pack();
    }

    private void jButton2ActionPerformed(ActionEvent evt) {
        oek.odswiezPodsumowanie();
        dispose();
    }

    private void jButton1ActionPerformed(ActionEvent evt) {
        zakoncz();
    }

    private void jPanel1KeyPressed(KeyEvent evt) {
        KeyEvent _tmp = evt;
        if (evt.getKeyCode() == 10) {
            zakoncz();
        }
    }

    private void zakoncz() {
        try {
            mtn.addRow(Float.parseFloat(jTextField1.getText().replace(",", ".")), Integer.parseInt(jTextField2.getText()));
            oek.odswiezPodsumowanie();
            dispose();
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "B\u0142ad podczas wprowadzania danych - (sprawdz czy pola liczbowe nie zawieraj\u0105 liter \noraz u\u017Cywaj kropki do oddzielenia cz\u0119\u015Bci u\u0142amkowej)");
        }
    }
    private MTNaleznosci mtn;
    private OEKlient oek;
    private JButton jButton1;
    private JButton jButton2;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JPanel jPanel1;
    private JTextField jTextField1;
    private JTextField jTextField2;
}
